<template>
	<view class="moreRanking">
		<view class="list">
			<u-swipe-action class="action" :show="item.show" :index="index" v-for="(item, index) in list" :key="item.id" @click="click" :options="options">
				<view class="item" @click="toSongSheet(index)">
					<view class="left">
						<view class="title">{{ item.musicListName }}</view>
						<image :src="pubUrl + item.musicListImg" class="cover"></image>
					</view>

					<view class="right" v-if="show">
						<view class="rightList">
							<view class="rightItem" v-for="(item2, index2) in songList[index]" :key="index2">
								<view class="title">{{ item2.musicName }}-{{ item2.musicAuthor }}</view>
							</view>
						</view>
					</view>
				</view>
			</u-swipe-action>
		</view>
		<!-- <view class="addMenu">
		+
	</view> -->
	</view>
</template>

<script>
import { musiclistgetallbyuser, getbymusiclist, musiclistdelete } from '@/api/song';
import { pubUrl } from '@/api/http.js';

export default {
	data() {
		return {
			list: [],
			pubUrl: pubUrl,
			songList: [],
			show: false,
			show: false,
			options: [
				{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}
			]
		};
	},
	methods: {
		click(index) {
			console.log(this.list[index].id)
			this.musiclistdeleteApi(this.list[index].id);
		},
		//删除歌单
		musiclistdeleteApi(id) {
			musiclistdelete({ id: id }).then(res => {
				console.log(res);
				this.musiclistgetallbyuserApi();
			});
		},
		//查询当前用户创建的歌单
		musiclistgetallbyuserApi() {
			musiclistgetallbyuser().then(res => {
				this.list = res.data;
				this.getbymusiclistApi();
			});
		},
		//查询所有的歌单里面的歌曲
		getbymusiclistApi(index = 0) {
			getbymusiclist({ id: this.list[index].id }).then(res => {
				this.songList[index] = res.data;
				if (++index != this.list.length) {
					this.getbymusiclistApi(index);
				} else {
					this.show = true;
				}
			});
		},
		//跳转歌单详情
		toSongSheet(index) {
			uni.navigateTo({
				url: '/pages/songSheet/songSheet?id=' + this.list[index].id
			});
		}
	},

	onLoad() {
		this.musiclistgetallbyuserApi();
	}
};
</script>

<style lang="less" scoped>
.moreRanking {
	.addMenu {
		border-radius: 100%;
		background-color: green;
		width: 40px;
		height: 40px;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
		font-size: 20px;
		position: fixed;
		right: 10px;
		bottom: 150px;
	}
	.list {
		width: calc(100% - 10px);
		height: 100%;
		overflow-y: scroll;
		.action {
			width: 100%;
			margin-top: 10px;
		}
		.item {
			width: calc(100% - 20px);
			margin-left: 10px;
			background-color: #351a23;
			//margin: 10px;
			border-radius: 15px;
			//padding: 10px;
			display: flex;
			.left {
				margin-left: 10px;
				.title {
					color: #b0295d;
					font-weight: 600;
					padding-top: 10px;
					width: 80px;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				.cover {
					width: 50px;
					height: 50px;
					border-radius: 5px;
					margin-top: 5px;
				}
			}
			.right {
				padding-top: 10px;
				color: #bfbfbf;
				margin-left: 10px;
				display: flex;
				align-items: center;
				position: absolute;
				left: 100px;
				.rightItem {
					margin-top: 5px;
				}
			}
		}
	}
}
</style>
